<template>
  <div class="outmain ba_f">
    <div class="ba_f outmain">
      <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
        <el-tab-pane label="排队取号" name="storequeuingdetails"></el-tab-pane>
        <el-tab-pane label="桌位类型" name="storequeuingtype"></el-tab-pane>
        <el-tab-pane label="排队设置" name="storequeuingset"></el-tab-pane>
      </el-tabs>
    </div>
    <div class="ba_f">
      <div class="shuju_title mar_b20">
        <div class="shuju_title_text">
          <span>排队设置</span>
        </div>
      </div>
      <el-form ref="form" :model="form" label-width="180px">
        <el-form-item label="排队语音文字">
          <el-input v-model="form.please" placeholder="请">
            <template slot="append">A001</template>
          </el-input>
          <el-input v-model="form.content" placeholder="号用餐" class="qucan"></el-input>
        </el-form-item>
        <el-form-item label="小票打印">
          <el-radio-group v-model="form.orderPrint">
            <el-radio label="1">取号后自动打印</el-radio>
            <el-radio label="2">手动打印</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="取号规则">
          <baidu-ueditor :content="form.details" @ueditor="getUeditor"></baidu-ueditor>
        </el-form-item>
      </el-form>
    </div>
    <div class="mar_t20 ba_f pad_20 t_c">
      <el-button type="primary" @click="submitForm">保存</el-button>
    </div>
  </div>
</template>
<script>
import { getStoreConfig, postStoreConfig } from '@/api/setup';
import baiduUeditor from '@/plugins/baidu-ueditor';
import {mapState} from "vuex";
export default {
  components: { baiduUeditor },
  created() {
    this.init();
  },
  computed: {
    ...mapState(['storeId']),
  },
  data() {
    return {
      activeName: 'storequeuingset',
      form: {
        orderPrint: '1',
        please: '',
        content: '',
        details: '',
      }
    };
  },
  methods: {
    handleClick() {
      if (this.activeName == 'storequeuingdetails') {
        this.$router.push({path: 'storequeuingdetails'});
      } else if (this.activeName == 'storequeuingtype') {
        this.$router.push({path: 'storequeuingtype'});
      }else if (this.activeName == 'storequeuingset') {
        this.$router.push({path: 'storequeuingset'});
      }
    },
    getUeditor(content) {
      this.form.details = content;
    },
    async init() {
      const { data } = await getStoreConfig({ ident: 'queuing',storeId:this.storeId,});
      this.form2 = this.form;
      this.form = Object.assign(this.form2, data);
    },
    submitForm() {
      this.$refs['form'].validate(async (valid) => {
        if (valid) {
          this.form.ident = 'queuing';
          this.form.identName = '排队配置';
          this.form.storeId = this.storeId;
          const { msg } = await postStoreConfig(this.form);
          this.$baseMessage(msg, 'success');
          this.init();
        } else {
          return false;
        }
      });
    }
  }
};
</script>
